//
//  RZKTabbarController.m
//  WSHBussiness
//
//  Created by 💋        任泽坤　 on 2017/11/29.
//  Copyright © 2017年 💋        任泽坤　. All rights reserved.
//

#import "RZKTabbarController.h"

#import "RZKMineViewController.h"

#import "RZKNavigationController.h"

@interface RZKTabbarController (){
    
   
    
    /*//2.0 版本优化
    NSArray * TabBarImgArr;
    NSArray * TabBarSelectImgArr;
    NSArray * TabBarTitleArr;
    NSArray * ChildViewControllers;
    */
 
}
//3.0版本优化
@property(nonatomic,strong)NSArray * tabbarMessageArr;//用来获取从Plist中存储到的数据
@end

@implementation RZKTabbarController

#pragma mark -- 终极优化版
-(NSArray *)tabbarMessageArr{
    
    if (!_tabbarMessageArr) {
        _tabbarMessageArr = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"RZKTabbarControllers" ofType:@"plist"]];
    }
    return _tabbarMessageArr;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    UITabBarItem * item= [UITabBarItem appearance];
            //未选中的tabbar字体颜色;
    [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0f],NSForegroundColorAttributeName:[UIColor grayColor]} forState:UIControlStateNormal];
            //选中tabbar 字体颜色;
    [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0f],NSForegroundColorAttributeName:[UIColor colorWithRed:57/255.0 green:167/255.0 blue:241 /255.0 alpha:1]} forState:UIControlStateSelected];
    
    
//终极版本
    //注意这里一定要用 self. 去访问上边的setter 方法 (通过self.xxx 通过访问的方法的引用：包含了set和get方法。而通过下划线是获取自己的实例变量，不包含set和get的方法。)
    for (NSDictionary * dic in self.tabbarMessageArr) {
        Class viewControllerClass = NSClassFromString(dic[@"TabbarController"]);
        UIViewController * viewController = [[viewControllerClass alloc]init];
        viewController.tabBarItem.image = [UIImage imageNamed:dic[@"TabbarImg"]];
        viewController.tabBarItem.selectedImage = [UIImage imageNamed:dic[@"TabbarSelImg"]];
        //viewController.tabBarItem.title = dic[@"TabbarTitle"];
        //设置导航条标签
        viewController.title = dic[@"TabbarTitle"];
        //将viewController 添加到导航条上
        RZKNavigationController * nav = [[RZKNavigationController alloc]initWithRootViewController:viewController];
        //将导航条添加到tabbar 上
        [self addChildViewController:nav];
        
    }

    
    
#pragma mark -- 2.0版本优化
//    RZKTimeViewController * timeVc = [[RZKTimeViewController alloc]init];
//    RZKClassViewController * classVc = [[RZKClassViewController alloc]init];
//    RZKBuyCarViewController * buycarVc = [[RZKBuyCarViewController alloc]init];
//    RZKMineViewController * mineVc = [[RZKMineViewController alloc]init];
//
//    TabBarImgArr = @[@"菜单栏限时特卖按钮未选中状态",@"菜单栏分类按钮未选中状态",@"菜单栏购物车按钮未选中状态",@"菜单栏我的按钮未选中状态"];
//    TabBarSelectImgArr = @[@"菜单栏限时特卖按钮选中状态",@"菜单栏分类按钮选中状态",@"菜单栏购物车按钮选中状态",@"菜单栏我的按钮选中状态"];
//    TabBarTitleArr = @[@"限时购",@"分类",@"购物车",@"我的"];
//    ChildViewControllers = @[timeVc,classVc,buycarVc,mineVc];
//    NSDictionary * tabbarDic = @{@"tabbarImg":TabBarImgArr,@"tabbarSelImg":TabBarSelectImgArr,@"tabbarTitle":TabBarTitleArr,@"viewControllers":ChildViewControllers};
//
//
//
//    for (int i = 0; i<TabBarImgArr.count; i++) {
//
//        UIViewController * viewController = [tabbarDic[@"viewControllers"] objectAtIndex:i];
//        viewController.tabBarItem.image = [UIImage imageNamed:[tabbarDic[@"tabbarImg"]objectAtIndex:i]];
//        viewController.tabBarItem.selectedImage = [UIImage imageNamed:[tabbarDic[@"tabbarSelImg"]objectAtIndex:i]];;
//        viewController.tabBarItem.title =[tabbarDic[@"tabbarTitle"]objectAtIndex:i];
//
//        //未选中的tabbar字体颜色;
//        [viewController.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0f],NSForegroundColorAttributeName:[UIColor grayColor]} forState:UIControlStateNormal];
//        //选中tabbar 字体颜色;
//        [viewController.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0f],NSForegroundColorAttributeName:[UIColor colorWithRed:57/255.0 green:167/255.0 blue:241 /255.0 alpha:1]} forState:UIControlStateSelected];
//
//        [self addChildViewController:viewController];
//    }
    
#pragma mark -- 1.0版本优化
    //==创建子视图控制器==//
    
    //优化版本1.0//_appearance 外观,样式
    //设置所有 TabbarItem 的文字属性  xcode 5.0 以后添加的方法
//    UITabBarItem * item = [UITabBarItem appearance];
//     [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0f],NSForegroundColorAttributeName:[UIColor grayColor]} forState:UIControlStateNormal];
//     [item setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0f],NSForegroundColorAttributeName:[UIColor colorWithRed:57/255.0 green:167/255.0 blue:241 /255.0 alpha:1]} forState:UIControlStateSelected];
//
//    RZKTimeViewController * timeVc = [[RZKTimeViewController alloc]init];
   
    
    
    //Item 图片的处理
    /*/如果选中图片没有变成本图片的渲染 那么要 改变选中图片的渲染方式  也可以在图层里 Render as 选择 Original
     UIImage * image = [UIImage imageNamed:@"菜单栏限时特卖按钮未选中状态"];
     image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];//image 始终用原图进行渲染
     UIImage * selectimage = [UIImage imageNamed:@"菜单栏限时特卖按钮选中状态"];
     selectimage = [selectimage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
     viewControl1.tabBarItem.selectedImage = selectimage;
     *////
//    timeVc.tabBarItem.image = [UIImage imageNamed:@"菜单栏限时特卖按钮未选中状态"];
//    timeVc.tabBarItem.selectedImage = [UIImage imageNamed:@"菜单栏限时特卖按钮选中状态"];
 
//    timeVc.tabBarItem.title = @"限时购";
    //未选中状态 文字 的颜色
//    [viewControl1.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0f],NSForegroundColorAttributeName:[UIColor grayColor]} forState:UIControlStateNormal];
//    //选中状态的 文字 的颜色
//    [viewControl1.tabBarItem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12.0f],NSForegroundColorAttributeName:[UIColor colorWithRed:57/255.0 green:167/255.0 blue:241 /255.0 alpha:1]} forState:UIControlStateSelected];
    
//将controller 添加到tabbar 上
//    [self addChildViewController:timeVc];
  
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
